//
//  HJGroupIntroductionCell.m
//  KaiChat
//
//  Created by lx on 2023/11/6.
//

#import "HJGroupIntroductionCell.h"
#import "HJChatGroupModel.h"

@interface HJGroupIntroductionCell()

@property (nonatomic, weak) UIImageView *avatarImageView;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *introductionLabel;

@end


@implementation HJGroupIntroductionCell


- (void)settingSubView {
    [super settingSubView];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *avatarImageView = [UIImageView addToView:self.contentView];
    avatarImageView.addCornerRadius(23);
    avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
    [avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.inset(leftRightMargin);
        make.width.height.offset(50);
        make.centerY.offset(-5);
    }];
    
    UILabel *nameLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMediumMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(avatarImageView).offset(4);
        make.left.equalTo(avatarImageView.mas_right).offset(10);
    }];
    
    UILabel *introductionLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(13) color:UIColor.tj_868391Color title:nil textAlignment:NSTextAlignmentLeft];
    [introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLabel.mas_bottom).offset(10);
        make.left.equalTo(nameLabel);
        make.right.inset(leftRightMargin);
    }];
    
    UIButton *editButton = [UIButton addToView:self.contentView];
    [editButton setImage:[UIImage imageNamed:@"edit_icon"] forState:UIControlStateNormal];
    [editButton addTarget:self action:@selector(didClickEditButton) forControlEvents:UIControlEventTouchUpInside];
    [editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(leftRightMargin - 5);
        make.centerY.equalTo(nameLabel);
        make.width.height.offset(30);
    }];
    
    _avatarImageView = avatarImageView;
    _nameLabel = nameLabel;
    _introductionLabel = introductionLabel;
    
}

- (void)didClickEditButton {
    if (_didClickEditButtonBlock) {
        _didClickEditButtonBlock();
    }
}

- (void)setModel:(HJCellModel *)model {
    _model = model;
    
    HJChatGroupModel *groupModel = model.anyObject;
    [_avatarImageView tj_setImageWithUrl:groupModel.avatar placeholderImage:[UIImage imageNamed:defaultAvatarName]];
    _nameLabel.text = groupModel.name;
    _introductionLabel.text = groupModel.intro;
}

@end
